var express = require('express')
var app = new express()
var mongoose = require('mongoose')
var user = require('./router/user')
var totalImage = require('./router/totalImage')
var url = "mongodb://localhost:27017/test"

mongoose.connect(url, (err) => {
    if (err) {
        console.log(err)
    } else {
        console.log('Mongodb connect success')
    }
})

bodyParser = require('body-parser')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false}))

app.use('/api/users', user) // 将路由注册到/users的路径下
app.use('/api/totalImages', totalImage)

var port = process.env.PORT || 3000

app.listen(port)
console.log('app is listening on port: ' + port)